package com.xixibaby.message.channel.dingding;

import com.xixibaby.core.message.BaseChannel;

import java.util.Map;
/**
 * @author tooomj
 */
public class DingdingChannel extends BaseChannel {

    private final String templet;

    private final Integer msgtype;

    private String title;

    @Override
    public Integer code() {
        return 2;
    }

    @Override
    protected void beforeHandler(Map<String, Object> context) {
        context.put( "msgtype", MSGTYPE[msgtype]);
        context.put( "context", templet);
        if(msgtype == 1){
            DDMessage.Markdown markdown = new DDMessage.Markdown();
            markdown.setTitle(this.title);
            context.put("markdown",markdown);
        }
    }

    @Override
    protected void cleanMap(Map<String, Object> context) {
        context.remove("msgtype");
        context.remove("context");
        if(msgtype == 1){
            context.remove("markdown");
        }
    }

    @Override
    protected String[] defaultFormat() {
        return new String[]{"context","text"};
    }

    public enum DDMsgTYpe{
        TEXT,MARKDOWN,LINK,ACTION_CARD
    }

    private static final String[] MSGTYPE = new String[]{
            "text","markdown","link","actionCard"
    };

    public DingdingChannel(String title,String templet,DDMsgTYpe msgtype) {
        this.templet = templet;
        this.msgtype = msgtype.ordinal();
        this.title = title;
    }

    public DingdingChannel(String templet) {
        this.templet = templet;
        this.msgtype = 0;
    }




}
